package com.ruoyi.system.chaincode.controller;

import com.ruoyi.business.domain.Chain;
import com.ruoyi.business.service.ChainService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class FabricService {

    @Resource
    private ContractService contractService;

    @Resource
    private ChainService chainService;

    @Resource
    private ISysUserService userService;


    public boolean registerUser(SysUser user) {
        String type = "USER";
        String userName = user.getUserName();

        ChainAsset asset = new ChainAsset();
        {
            asset.setAssetKey(type + ":" + userName);
            asset.setAssetType(type);
            asset.setAssetName("REGISTER:" + userName);
            asset.setOwner(userName);
        }

        String s = contractService.registerUser(asset);
        userService.updateUser(user);

        Chain chain = new Chain();
        chainService.save(chain);
        return true;
    }

}
